<!DOCTYPE html>
<html lang="ch-zn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="./node_modules/bootstrap-icons/font/bootstrap-icons.css">
    <title>注册</title>
    <script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>
    <style>
        * {
            user-select: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <nav class="navbar navbar-expand-lg bg-body-tertiary">
            <div class="container-fluid">
                <a class="navbar-brand" href="./index.html">图书管理系统</a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">图书管理</a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="./bookquery.html">图书查询</a></li>
                                <li><a class="dropdown-item" href="./bookchange.html">图书更改</a></li>
                            </ul>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">学生入口</a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="./signup.html">新生注册</a></li>
                                <li>
                                    <hr class="dropdown-divider">
                                </li>
                                <li><a class="dropdown-item" href="./borrowbook.html">我要借书</a></li>
                                <li><a class="dropdown-item" href="./returnbook.html">我要还书</a></li>
                            </ul>
                        </li>
                    </ul>
                    <form class="d-flex" role="search">
                        <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
                        <button class="btn btn-outline-success" type="submit">Search</button>
                    </form>
                </div>

            </div>
        </nav>
        <br/>

        <div class="row">
            <div class="input-group mb-3">
                <span class="input-group-text">学生证号</span>
                <input type="text" class="form-control" placeholder="Id number" id="Id" aria-label="Id" aria-describedby="basic-addon1">
            </div>
            <div class="input-group mb-3">
                <span class="input-group-text">学生姓名</span>
                <input type="text" class="form-control" placeholder="Name" id="Name" aria-label="Name" aria-describedby="basic-addon1">
            </div>
            <div class="input-group mb-3">
                <span class="input-group-text">学生系别</span>
                <input type="text" class="form-control" placeholder="Affiliation" id="Affiliation" aria-label="Affiliation" aria-describedby="basic-addon1">
            </div>
            <div class="input-group mb-3">
                <span class="input-group-text">学生所学专业</span>
                <input type="text" class="form-control" placeholder="Major" id="Major" aria-label="Major" aria-describedby="basic-addon1">
            </div>
            <div class="input-group mb-3">
                <span class="input-group-text">借书上限数</span>
                <input type="number" class="form-control" placeholder="Max borrow" id="Max_borrow" aria-label="Max borrow" aria-describedby="basic-addon1">
            </div>
        </div>

        <div class="d-grid gap-2 col-4 mx-auto">
            <button class="btn btn-primary" type="button" onclick="signUp()">注册</button>
        </div>
    </div>
</body>
<script type="text/javascript" src="./node_modules/jquery/dist/jquery.js" charset="UTF-8"></script>
<script>
    url_head = 'http://www.library.com/index.php/'

    function signUp() {
        var input_id = document.getElementById('Id').value;
        var input_name = document.getElementById('Name').value;
        var input_affiliation = document.getElementById('Affiliation').value;
        var input_major = document.getElementById('Major').value;
        var input_max_borrow = document.getElementById('Max_borrow').value;
        if (input_id == "" | input_name == "" | input_affiliation == "" | input_major == "" | input_max_borrow == "") {
            alert("不得有空值");
            return;
        }
        var url0 = url_head + "Mysql/mysql_student_add_byid/input_id/" + input_id + "/input_name/" + input_name + "/input_affiliation/" + input_affiliation + "/input_major/" + input_major + "/input_max_borrow/" + input_max_borrow + "/"
        $.ajax({
            url: url0,
            async: pageYOffset,
            contentType: "application/x-www-form-urlencoded",
            dataType: "json",
            success: function(data) {
                if (data == "error:not empty") {
                    alert('该用户已存在！');
                    return 0;
                } else {
                    alert('已添加该用户！')
                    return 0;
                }
            },
            error: function(err) {
                // 请求失败， err是失败的内容
                print("请求失败");
            },
            complete: function(e) {
                // 不管成功还是失败都会调用这个函数
            }
        })
    }
</script>

</html>